from openai import OpenAI

# 请将 "your-api-key-here" 替换为你的实际 API Key
client = OpenAI(api_key="sk-5f87292120454a4b9ab0372ed9aa1a18", base_url="https://api.deepseek.com")

# 初始化消息历史，包含系统提示
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
]

# 持续对话
while True:
    # 获取用户输入
    user_input = input("You: ")
    
    # 如果用户输入 "exit"，退出对话
    if user_input.lower() == "exit":
        print("Goodbye!")
        break
    
    # 将用户输入添加到消息历史
    messages.append({"role": "user", "content": user_input})
    
    # 调用 API 获取回复
    response = client.chat.completions.create(
        model="deepseek-chat",  # 确保模型名称正确
        messages=messages,
        stream=False
    )
    
    # 获取助手的回复
    assistant_reply = response.choices[0].message.content
    
    # 将助手的回复添加到消息历史
    messages.append({"role": "assistant", "content": assistant_reply})
    
    # 打印助手的回复
    print(f"Assistant: {assistant_reply}")